package com.example.healthmanagement.service;


import com.example.healthmanagement.dao.CookBookRepository;
import com.example.healthmanagement.dao.UserRepository;
import com.example.healthmanagement.entity.CookBook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CookBookService {

    private final CookBookRepository cookBookRepository;


    @Autowired
    public CookBookService(CookBookRepository cookBookRepository) {
        this.cookBookRepository = cookBookRepository;
    }

    public boolean addCookBook(CookBook cookBook) {
        if (cookBookRepository.save(cookBook) != null) {
            return true;
        } else {
            return false;
        }
    }

    public boolean updateCookBook(CookBook cookBook) {
        cookBookRepository.save(cookBook);
        return true;
    }

    public List<CookBook> findAll(String bookName) {
        if (bookName != null) {
            return cookBookRepository.findCookBooksByDeletedAndBookNameContaining(false, bookName);
        } else {
            return cookBookRepository.getCookBooksByDeleted(false);
        }
    }

    public CookBook findCookBookById(int id) {
        return cookBookRepository.findCookBookByIdAndDeleted(id, false);
    }
}
